<?php
namespace Mob \ Controller;

use Think \ Controller;
use Think \ Hook;

class NoticeController extends BaseController {

    private $UserInfo;


	/**
	 * 主页面显示
	 */
	public function index() {

    $this->display();


	}

   public function newSend()
   {

 // <p class="font"> 模板不存在::./Application/Mob/View/default/Notice/newsend.html</p>

    $activityId = I('activityId');


    $Uid = get_uid();
    if($activityId)
    {
      $activity = D('Activity')->queryActivity($activityId);

     if($activity['sponsorUid']==$Uid)
    {
    $isIssue = D('Notice')->isIssue($activityId,$activity['sponsorUid']);
    if(!$isIssue)
    {
    $this->assign('activityId',$activityId);
    $this->display();
    }else
    {
     print_r('error');
     }
    }


    }else
    {
     print_r('parm is error!');


    }



   }


     public function doSend()
    {
        $aContent = I('post.content', '', 'op_t');
        $aType = I('post.type', 'image', 'op_t');
        $aAttachIds = I('post.attach_ids', '', 'op_t');
        $activityId = I('post.activityId','','string');
        $Uid = get_uid();

         $act= D('Activity');
         $activity = $act->queryActivity($activityId);
       if(empty($activity)||$activity['sponsorUid']!=$Uid)
       {
       //	$this->error('操作非法');
       print_r('Invalid Argument');
       return;
       }

        //  dump($aContent);exit;

        //权限判断
        if (!is_login()) {
         //   $this->error('请登陆后再进行操作');
         print_r('is not login');
        }



        if (empty($aContent)) {
          //  $this->error('发布内容不能为空。');
          print_r('contents is null');
        }

        $title = $activity['Title'];
        $feed_data = array();
        $feed_data['attach_ids'] = $aAttachIds;
        if (empty($aAttachIds)) {
            $aType = 'feed';
        }

        $noticeId = D('Notice')->sendNotice($activityId,$title,$aContent,$aType,$feed_data);
       if($noticeId)
       {
       $res = $act->updateBusinessId($activityId,$noticeId);


       }

       $this->redirect('Activity/settingActivity',array('activityId'=>$activityId,'businessId'=>$noticeId));


    }













}



